package com.rem.designPattern.chainOfResponsibility责任链;

import java.math.BigDecimal;

/**
 * 审批人对象
 *
 * @author Rem
 * @date 2022-11-27
 */
public abstract class Approver {
    protected Approver nextApprover;
    protected String name;

    public Approver(String name) {
        this.name = name;
    }

    /**
     * 设置后继者
     *
     * @param nextApprover
     */
    public void setNextApprover(Approver nextApprover) {
        this.nextApprover = nextApprover;
    }

    /**
     * 处理请求的方法
     *
     * @param purchaseRequest
     */
    public abstract void processRequest(PurchaseRequest purchaseRequest);
}

/**
 * 教学主任审批人
 */
class TeachDirectorApprover extends Approver {
    public TeachDirectorApprover(String name) {
        super(name);
    }

    @Override
    public void processRequest(PurchaseRequest purchaseRequest) {
        if (purchaseRequest.getPrice().compareTo(new BigDecimal(5000)) <= 0) {
            System.out.println("处理人：" + this.name);
        } else {
            nextApprover.processRequest(purchaseRequest);
        }
    }
}

/**
 * 院长审批人
 */
class DepartmentHeadApprover extends Approver {
    public DepartmentHeadApprover(String name) {
        super(name);
    }

    @Override
    public void processRequest(PurchaseRequest purchaseRequest) {
        if (purchaseRequest.getPrice().compareTo(new BigDecimal(5000)) > 0
                && purchaseRequest.getPrice().compareTo(new BigDecimal(10000)) <= 0) {
            System.out.println("处理人：" + this.name);
        } else {
            nextApprover.processRequest(purchaseRequest);
        }
    }
}

/**
 * 副校长审批人
 */
class ViceChancellorApprover extends Approver {
    public ViceChancellorApprover(String name) {
        super(name);
    }

    @Override
    public void processRequest(PurchaseRequest purchaseRequest) {
        if (purchaseRequest.getPrice().compareTo(new BigDecimal(10000)) > 0
                && purchaseRequest.getPrice().compareTo(new BigDecimal(30000)) <= 0) {
            System.out.println("处理人：" + this.name);
        } else {
            nextApprover.processRequest(purchaseRequest);
        }
    }
}

/**
 * 校长审批人
 */
class ChancellorApprover extends Approver {
    public ChancellorApprover(String name) {
        super(name);
    }

    @Override
    public void processRequest(PurchaseRequest purchaseRequest) {
        if (purchaseRequest.getPrice().compareTo(new BigDecimal(30000)) > 0) {
            System.out.println("处理人：" + this.name);
        } else {
            nextApprover.processRequest(purchaseRequest);
        }
    }
}
